/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package servlet;

import dao.BookDao;
import dao.MemberDao;
import entity.Book;
import entity.Member;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebServlet("/index")
public class GetAllBookServlet extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session=req.getSession();
        if(session.getAttribute("isLogin")==null){
            List<Book> list=new BookDao().getAllUndeletedBook(); 
            req.setAttribute("bookList", list);
            req.getRequestDispatcher("/index.jsp").forward(req,resp);
        }
        else{
            String name=(String)req.getSession().getAttribute("username");
            Member member=new MemberDao().getMemberByName(name);
            List<Book> list=new BookDao().getBookByType(member.getLiketype());
            req.setAttribute("likelist",list);
            
            List<Book> list1=new BookDao().getAllUndeletedBook();
            req.setAttribute("bookList", list1);
            
            req.getRequestDispatcher("/index.jsp").forward(req,resp);
        }
    }
    
}
